<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body></body>
</html>
<script>
    const str = `
        https://www.baidu.com 百度一下，你就知道
        http://www.google.com 谷歌搜索
    `;
    const regx = /https?:\/\/(www\.\w+\.(com|cn|net|org))/gi;
    const res = str.replace(regx, `<a href="$1">$1</a>`);
    console.log(res); // <a href="www.baidu.com">www.baidu.com</a> 百度一下，你就知道 <a href="www.google.com">www.google.com</a> 谷歌搜索
</script>
